package com.cy.myblog.action.menu;

import com.cy.myblog.action.BaseAction;
import com.cy.myblog.model.Tmenu;
import com.cy.myblog.pageModel.Json;
import com.cy.myblog.service.MenuServiceI;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/9/2.
 */
public class ResourceAction extends BaseAction {
    private static final long serialVersionUID = -425259218216321154L;
    private Json json = null;
    private Long total = 0L;
    private List rows  = new ArrayList();

    private Tmenu tmenu = new Tmenu();

    private MenuServiceI menuService;

    @Resource(name = "menuSerivce")
    public void setMenuService(MenuServiceI menuService) {
        this.menuService = menuService;
    }

    public String treeGrid(){
        rows = menuService.queryGrid().getRows();
        return TOJSON;
    }

    public String save(){
        json = new Json();

        try{
            menuService.save(tmenu);
            json.setSuccess(true);
        }catch(Exception e){
            e.printStackTrace();
            json.setSuccess(false);
            json.setMsg("存储失败!");
        }

        return TOJSON;
    }

    public String delete()
    {
        json = new Json();
        try{
            menuService.delete(tmenu.getId());
            json.setSuccess(true);
        }catch (Exception e){
            e.printStackTrace();
            json.setMsg("删除失败!");
        }

        return TOJSON;
    }

    public void queryEazyUITree()
    {
        writeJson(menuService.queryEazyUiTree());
    }

    public Tmenu getTmenu() {
        return tmenu;
    }

    public void setTmenu(Tmenu tmenu) {
        this.tmenu = tmenu;
    }

    public Json getJson() {
        return json;
    }

    public void setJson(Json json) {
        this.json = json;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public List getRows() {
        return rows;
    }

    public void setRows(List rows) {
        this.rows = rows;
    }
}
